package com.scorpionstudio.girlstoryshop.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.loopj.android.image.SmartImageView;
import com.scorpionstudio.girlstoryshop.DetailClothesActivity;
import com.scorpionstudio.girlstoryshop.R;
import com.scorpionstudio.girlstoryshop.bean.ItemClothes;
import com.scorpionstudio.girlstoryshop.data.CacheItems;

public class TwoColumnAdapter extends ArrayAdapter<ItemClothes>{
	private LayoutInflater mInflater;
	private Activity mActivity;
	public TwoColumnAdapter(Activity context) {
		super(context, 1);
		this.mActivity = context;
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

    public void addAll(ArrayList<ItemClothes> list){
        for(ItemClothes item : list){
            add(item);
        }
    }
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder mHolder;
		final ItemClothes mHome = this.getItem(position);
		if(convertView == null){
			mHolder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.item_clothes, parent, false);
			mHolder.tvDescription = (TextView) convertView.findViewById(R.id.tv_home);
			mHolder.myAvata = (SmartImageView) convertView.findViewById(R.id.imv_home);
			mHolder.tvCost = (TextView) convertView.findViewById(R.id.items_cost);
			convertView.setTag(mHolder);
		}else{
			mHolder = (ViewHolder) convertView.getTag();
		}
         convertView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				CacheItems.getInstance().setmItem(mHome);
				Intent mIntent = new Intent(mActivity,DetailClothesActivity.class);
				mActivity.startActivityForResult(mIntent,100);
			}
		});
		mHolder.tvDescription.setText(mHome.getDescriptionImg());
		mHolder.myAvata.setImageUrl(mHome.getUrlImg());
		mHolder.tvCost.setText("Giá sản phẩm :" + mHome.getCostItems());
		return convertView;
	}
	class ViewHolder{
		private TextView tvDescription,tvCost;
		private SmartImageView myAvata;
	}

}